package br.com.lh.urabuilder.helper
{
	import br.com.lh.urabuilder.domain.xml.ConditionalAction;
	import br.com.lh.urabuilder.view.ActionComponent;
	import br.com.lh.urabuilder.view.properties.CondtionalPropertiesForm;
	import br.com.lh.urabuilder.view.properties.PropertiesForm;
	
	import flash.events.MouseEvent;
	import flash.geom.Point;
	
	import mx.controls.Image;
	import mx.core.UIComponent;
	import mx.managers.PopUpManager;
	
	public class PropertieHelper
	{
		private var parentComponent:UIComponent;
		
		public function PropertieHelper(parentComponent:UIComponent)
		{
			this.parentComponent = parentComponent;
		}
		
			public function openProperties(event:MouseEvent):void{
				var img:Image = Image(event.currentTarget);
				var component:ActionComponent = img.parent as ActionComponent;
				doOpen(component);
			
			}
			
			public function doOpen(component:ActionComponent):void{
				var form:PropertiesForm =getForm(component);
				PopUpManager.addPopUp(form,parentComponent,true);
				PopUpManager.centerPopUp(form);	
				form.y = parentComponent.y;
				form.component = component;
				form.updateValues();
				
			}
			
			private function getForm(component:ActionComponent):PropertiesForm{
				if (component.uraAction is ConditionalAction){
					return new CondtionalPropertiesForm();
				}
				return new PropertiesForm();
			}
			
			private function getCoordinates(component:ActionComponent):Point
			{
				var point:Point = new Point();
				point.x=component.x;
                point.y=component.y;                
				return point; 
			}
		

	}
}